[PR #9499/b45a7dab backport][3.11] Improve performance of creating the ConnectionKey #9500
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a backport of PR #9499 as merged into master (b45a7da).
What do these changes do?
Improve performance of the client by reducing the overhead to create the
ConnectionKey
objects.Reuses the same idea as aio-libs/yarl#1316 and aio-libs/yarl#1322
Calling
tuple.__new__
is much faster because it avoids the extra runtime lambda having to be run and arguments unpacked for every message https://github.com/python/cpython/blob/d83fcf8371f2f33c7797bc8f5423a8bca8c46e5c/Lib/collections/__init__.py#L441This only works if the object being created is a
NamedTuple
so this speed up is only recommended internally and should not be used outside ofaiohttp
since we do not guarantee that ConnectionKey will remain aNamedTuple
in the future.Are there changes in behavior for the user?
no
Is it a substantial burden for the maintainers to support this?
no